package seqlist.LeetCode;


public class Test {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};
        ListNode head = add(arr);
        System.out.println(day(head));
        Num_92_reverseBetween hll = new Num_92_reverseBetween();
        head = hll.reverseBetween(head, 2, 4);
        System.out.println(day(head));


    }

    //根据给整形数组创建一个相同的链表并返回
    public static ListNode add(int[] arr){
        ListNode head = new ListNode();
        ListNode prve = head;

        for (int i = 0; i < arr.length; i++) {
            ListNode node = new ListNode(arr[i]);
            prve.next = node;
            prve = node;
        }
        return head.next;
    }
    //打印链表方法
    public static String day(ListNode head){
        String rep = "";
        //一定要创建一个变量来变量，如果直接用
        //head来变量的话就丢失原来的地址，找不到头节点了
        for (ListNode x = head; x != null ; x = x.next) {
            //走到尾节点为null地址算结束
            rep += x.val;
            rep += " -> ";
        }
        rep += "NULL";//用来表示链表走到空了
        return rep;
    }
}
